import { Component, OnInit } from '@angular/core';
import { HttpClient,HttpHeaders} from '@angular/common/http';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  title = "用户登录"
  public logininfo: any = {
    email: '',
    password:''
  }
  constructor(public http:HttpClient) { }

  ngOnInit(): void {
  }
  
  login(){
    console.log(this.logininfo);
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type': 'application/json;charset=UTF-8',
        'Access-Control-Allow-Origin': '*',
      })
    };
    var api = "http://192.168.31.24:4200/login";
    this.http.post(api,this.logininfo, httpOptions).subscribe((response: any) => {
      let message = response.json()
      let tips = ''
      if(message.status == 1){
        tips = '登录成功\n'+'uid:'+message.uid
      }
      else{
        tips = '登录失败'
      }
      alert(tips)
    })
  }
}
